<template>
  <div class="el-main">
    <div style="background-color: white">
      <el-table
        :data="tableData"
        style="width: 100%;"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column
          type="index"
          width="width: 20%;">
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          style="width: 20%;"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="employee_id"
          label="工号"
          style="width: 20%;"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="phone"
          label="手机"
          style="width:20%"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="email"
          label="邮箱"
          style="width:20%"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作" style="width:20%">
          <template slot-scope="scope">
            <span style="cursor: pointer; color: cornflowerblue;" @click="useUser(scope.$index, scope.row)">启用</span>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: center;margin-top: 10px;">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 6, 7, 8]"
          :page-size="PageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="Total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  const axios = require('axios');
  export default {
    name: "DeleteUser",
    data() {
      return {
        currentPage: 1,
        PageSize: 5,
        Total:0,
        totalData:[],
        tableData: [],
      }
    },
    methods: {
      useUser(index, row) {
        this.$confirm('确定启用该账号吗？', '启用账号', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true,
          modal: false,
        }).then(() => {
          axios.post("/enableMember",{"id":row.id}).then(res=>{
            if(res.data = 0){
              this.$message({
                type: 'danger',
                message: '启用失败!'
              });
            }else{
              this.tableData.splice(index,1);
              this.$message({
                type: 'success',
                message: '启用成功!'
              });
            }
          })

        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消启用'
          });
        });
      },
      handleSizeChange(val) {
        this.PageSize = val;
        this.tableData = this.totalData.slice(0,this.PageSize);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.tableData = this.totalData.slice((this.currentPage-1) * this.PageSize,this.currentPage * this.PageSize);
      },
    },
    created() {
      setTimeout(() => {
        this.$parent.$parent.CheckDelete();
        this.$parent.$parent.ToShow();
      },100)
      axios.post("/getDisableUsers",{"id":window.localStorage.getItem("enterprise_id")}).then(res => {
        this.totalData = res.data;
        this.tableData = res.data.slice(0,this.PageSize);
        this.Total = res.data.length;
      })
    },
  }
</script>

<style scoped>
  .searchDepartment {
    margin-left: 20px;
    margin-top: 20px;
    width:300px;
  }
</style>
